<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.1.1">
<meta name="baidu-site-verification" content="code-hkfwkpUecU" />
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="true">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic|Roboto+Slab:300,300italic,400,400italic,700,700italic|PT+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.14.0/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"github.com","root":"/","scheme":"Gemini","version":"8.0.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"disqus","storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>

  <meta property="og:type" content="website">
<meta property="og:title" content="shanlu的博客">
<meta property="og:url" content="https://github.com/shanlu123/page/6/index.html">
<meta property="og:site_name" content="shanlu的博客">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="shanlu">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://github.com/shanlu123/page/6/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>shanlu的博客</title>
  






  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>
  <a href="https://github.com/shanlu123" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">shanlu的博客</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">三餐四季，冷暖自知</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/home" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-前端">

    <a href="/%E5%89%8D%E7%AB%AF/" rel="section"><i class="fa fa-cloud fa-fw"></i>前端</a>

  </li>
        <li class="menu-item menu-item-生活">

    <a href="/%E7%94%9F%E6%B4%BB/" rel="section"><i class="fa fa-user fa-fw"></i>生活</a>

  </li>
        <li class="menu-item menu-item-school">

    <a href="/school/" rel="section"><i class="fa fa-graduation-cap fa-fw"></i>学校</a>

  </li>
        <li class="menu-item menu-item-tree_hole">

    <a href="/tree_hole/" rel="section"><i class="fa fa-tree fa-fw"></i>树洞</a>

  </li>
        <li class="menu-item menu-item-photos">

    <a href="/photos/" rel="section"><i class="fa fa-camera fa-fw"></i>相册</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <section class="post-toc-wrap sidebar-panel">
      </section>
      <!--/noindex-->

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="shanlu"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">shanlu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">127</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/shanlu123" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;shanlu123"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.cnblogs.com/shanlu0000/p/11478994.html" title="博客园 → https:&#x2F;&#x2F;www.cnblogs.com&#x2F;shanlu0000&#x2F;p&#x2F;11478994.html" rel="noopener" target="_blank"><i class="fa fa-blog fa-fw"></i>博客园</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:yourname@gmail.com" title="E-Mail → mailto:yourname@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/6662419816/home?wvr=5" title="微博 → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;6662419816&#x2F;home?wvr&#x3D;5" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>微博</a>
      </span>
  </div>


  <div class="links-of-blogroll animated">
    <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://www.npmjs.com/" title="https:&#x2F;&#x2F;www.npmjs.com&#x2F;" rel="noopener" target="_blank">npm</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://www.bilibili.com/" title="https:&#x2F;&#x2F;www.bilibili.com&#x2F;" rel="noopener" target="_blank">bilibili</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://stackoverflow.com/" title="https:&#x2F;&#x2F;stackoverflow.com&#x2F;" rel="noopener" target="_blank">stackoverflow</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://developers.weixin.qq.com/miniprogram/dev/component/" title="https:&#x2F;&#x2F;developers.weixin.qq.com&#x2F;miniprogram&#x2F;dev&#x2F;component&#x2F;" rel="noopener" target="_blank">小程序</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://www.ruanyifeng.com/blog/" title="http:&#x2F;&#x2F;www.ruanyifeng.com&#x2F;blog&#x2F;" rel="noopener" target="_blank">阮一峰</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://cn.aliyun.com/" title="https:&#x2F;&#x2F;cn.aliyun.com&#x2F;" rel="noopener" target="_blank">阿里云</a>
        </li>
    </ul>
  </div>

      </section>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">
      

      
      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/12/03/%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0/%E3%80%8A%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0%E3%80%8B2.5%E5%B0%8F%E8%8A%82%E2%80%94%E2%80%94CC++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8-%E6%95%B0%E7%BB%84/%E4%B9%A0%E9%A2%986-6%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/12/03/%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0/%E3%80%8A%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0%E3%80%8B2.5%E5%B0%8F%E8%8A%82%E2%80%94%E2%80%94CC++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8-%E6%95%B0%E7%BB%84/%E4%B9%A0%E9%A2%986-6%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92/" class="post-title-link" itemprop="url">习题6-6 杨辉三角</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-03 00:00:00" itemprop="dateCreated datePublished" datetime="2020-12-03T00:00:00+08:00">2020-12-03</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2020-12-07 15:18:22" itemprop="dateModified" datetime="2020-12-07T15:18:22+08:00">2020-12-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/OJ-%E3%80%8A%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0%E3%80%8B/" itemprop="url" rel="index"><span itemprop="name">OJ--《算法笔记》</span></a>
        </span>
    </span>

  
    <span id="/2020/12/03/%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0/%E3%80%8A%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0%E3%80%8B2.5%E5%B0%8F%E8%8A%82%E2%80%94%E2%80%94CC++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8-%E6%95%B0%E7%BB%84/%E4%B9%A0%E9%A2%986-6%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92/" class="post-meta-item leancloud_visitors" data-flag-title="习题6-6 杨辉三角" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/12/03/%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0/%E3%80%8A%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0%E3%80%8B2.5%E5%B0%8F%E8%8A%82%E2%80%94%E2%80%94CC++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8-%E6%95%B0%E7%BB%84/%E4%B9%A0%E9%A2%986-6%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/12/03/%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0/%E3%80%8A%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0%E3%80%8B2.5%E5%B0%8F%E8%8A%82%E2%80%94%E2%80%94CC++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8-%E6%95%B0%E7%BB%84/%E4%B9%A0%E9%A2%986-6%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>660</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="题目描述："><a href="#题目描述：" class="headerlink" title="题目描述："></a>题目描述：</h3><figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">按要求输入如下格式的杨辉三角</span><br><span class="line"><span class="number">1</span></span><br><span class="line"><span class="number">1</span> <span class="number">1</span></span><br><span class="line"><span class="number">1</span> <span class="number">2</span> <span class="number">1</span></span><br><span class="line"><span class="number">1</span> <span class="number">3</span> <span class="number">3</span> <span class="number">1</span></span><br><span class="line"><span class="number">1</span> <span class="number">4</span> <span class="number">6</span> <span class="number">4</span> <span class="number">1</span></span><br><span class="line"><span class="number">1</span> <span class="number">5</span> <span class="number">10</span> <span class="number">10</span> <span class="number">5</span> <span class="number">1</span></span><br><span class="line"></span><br><span class="line">最多输出<span class="number">10</span>层</span><br></pre></td></tr></table></figure>

<h3 id="输入："><a href="#输入：" class="headerlink" title="输入："></a>输入：</h3><figure class="highlight excel"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">输入只包含一个正整数<span class="built_in">n</span>，表示将要输出的杨辉三角的层数。</span><br></pre></td></tr></table></figure>

<h3 id="输出："><a href="#输出：" class="headerlink" title="输出："></a>输出：</h3>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/12/03/%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0/%E3%80%8A%E7%AE%97%E6%B3%95%E7%AC%94%E8%AE%B0%E3%80%8B2.5%E5%B0%8F%E8%8A%82%E2%80%94%E2%80%94CC++%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8-%E6%95%B0%E7%BB%84/%E4%B9%A0%E9%A2%986-6%20%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/30/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%B0%8F%E5%93%BC%E4%B9%B0%E4%B9%A6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/30/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%B0%8F%E5%93%BC%E4%B9%B0%E4%B9%A6/" class="post-title-link" itemprop="url">小哼买书</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-11-30 00:00:00" itemprop="dateCreated datePublished" datetime="2020-11-30T00:00:00+08:00">2020-11-30</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2020-12-07 15:10:38" itemprop="dateModified" datetime="2020-12-07T15:10:38+08:00">2020-12-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/" itemprop="url" rel="index"><span itemprop="name">读书笔记-- 《啊哈算法》</span></a>
        </span>
    </span>

  
    <span id="/2020/11/30/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%B0%8F%E5%93%BC%E4%B9%B0%E4%B9%A6/" class="post-meta-item leancloud_visitors" data-flag-title="小哼买书" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/30/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%B0%8F%E5%93%BC%E4%B9%B0%E4%B9%A6/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/30/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%B0%8F%E5%93%BC%E4%B9%B0%E4%B9%A6/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="程序1："><a href="#程序1：" class="headerlink" title="程序1："></a>程序1：</h3><ul>
<li>输入：2行，第一行为一个正整数n表示有n个同学参与调查；第二行有n个用空格隔开的正整数，为每本书的ISBN号。</li>
<li>输出：2行，第一行为一个正整数k，表示需要买多少本书；第二行为k个用空格隔开的正整数，为从小到大已排好序的需要购买的图书的ISBN号。</li>
<li>程序运行时间限制为1秒</li>
</ul>
<h3 id="分析："><a href="#分析：" class="headerlink" title="分析："></a>分析：</h3><ol>
<li><p>两种方法：方法1，先将n个图书的ISBN号去重，再进行从小到大排序并输出。方法2，先从小到大排序，输出的时候再去重。</p>
</li>
<li><p>方法1：将桶排序稍加改动可以起到去重的效果</p>
<p>C代码：</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//方法1，先使用桶排序去重，再排序</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">	<span class="comment">//1，定义数组a存放全部图书的ISBN号的出现次数，变量n保存图书数量，因为ISBN号的范围在1-1000之间，故数组大小定义为1001;</span></span><br><span class="line">	<span class="keyword">int</span> a[<span class="number">1001</span>], n;</span><br><span class="line">	<span class="keyword">int</span> count = <span class="number">0</span>; <span class="comment">//count是去重后ISBN号的个数</span></span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;输入图书数量：&quot;</span>);</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;n);</span><br><span class="line"></span><br><span class="line">	<span class="comment">//2，将数组a初始化</span></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">1001</span>; i++) &#123;</span><br><span class="line">		a[i] = <span class="number">0</span>;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">//3,读入n个ISBN号</span></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;输入%d个图书的ISBN号：\n&quot;</span>,n);</span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++) &#123;</span><br><span class="line">		<span class="keyword">int</span> num = <span class="number">0</span>;</span><br><span class="line">		<span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;num);</span><br><span class="line">		a[num]=<span class="number">1</span>; <span class="comment">//标记出现过的ISBN号</span></span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">1001</span>; i++) &#123;</span><br><span class="line">		count += a[i];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>, count);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">1001</span>; i++) &#123;</span><br><span class="line">		<span class="keyword">if</span> (a[i] == <span class="number">1</span>) &#123; <span class="comment">//如果这个ISBN号出现过就打印出来</span></span><br><span class="line">			<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, i);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>输入图书数量：10<br>输入10个图书的ISBN号：<br>20 40 32 67 40 20 89 300 400 15</p>
<p>8<br>15 20 32 40 67 89 300 400</p>
<p>这种方法的时间复杂度就是桶排序的时间复杂度：O（M+N）</p>
</blockquote>
</li>
</ol>
<p>   python代码：</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/11/30/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%B0%8F%E5%93%BC%E4%B9%B0%E4%B9%A6/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%BA%8C/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%BA%8C/" class="post-title-link" itemprop="url">面向对象二</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-11-30 00:00:00" itemprop="dateCreated datePublished" datetime="2020-11-30T00:00:00+08:00">2020-11-30</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2020-12-07 14:47:00" itemprop="dateModified" datetime="2020-12-07T14:47:00+08:00">2020-12-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/javaSE/" itemprop="url" rel="index"><span itemprop="name">javaSE</span></a>
        </span>
    </span>

  
    <span id="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%BA%8C/" class="post-meta-item leancloud_visitors" data-flag-title="面向对象二" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%BA%8C/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%BA%8C/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>453</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="OOP特征一：封装与隐藏"><a href="#OOP特征一：封装与隐藏" class="headerlink" title="OOP特征一：封装与隐藏"></a>OOP特征一：封装与隐藏</h3><ol>
<li><p>封装：隐藏对象内部的复杂性，只对外公开简单的接口，便于外界调用，从而提高系统的可扩展性、可维护性。</p>
</li>
<li><p>Java中通过将数据声明为 private，再提供 public 方法：getXXX() 和 setXXX() 实现对成员变量的操作，以实现这些目的：</p>
<ul>
<li>隐藏一个类中不需要对外提供的实现细节，定义为 private只能在该类内部访问</li>
<li>使用者只能通过实现制定好的方法来访问数据，可以方便的加入逻辑控制，限制对属性的不合理操作</li>
<li>便于修改，增强代码的可维护性</li>
</ul>
</li>
<li><p>四种访问权限修饰符</p>
<table>
<thead>
<tr>
<th>修饰符</th>
<th>类内部</th>
<th>同一个包</th>
<th>不同包的子类</th>
<th>同一个工程</th>
</tr>
</thead>
<tbody><tr>
<td>private</td>
<td>yes</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>缺省</td>
<td>yes</td>
<td>yes</td>
<td></td>
<td></td>
</tr>
<tr>
<td>protected</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td></td>
</tr>
<tr>
<td>public</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
</tr>
</tbody></table>
</li>
<li><p>对于class的权限修饰只有 public 和 default(缺省)。public 类可以在任意地方被访问，default 类只可以被同一个包内部的类访问。</p>
</li>
</ol>
<h3 id="OOP特征二：继承性"><a href="#OOP特征二：继承性" class="headerlink" title="OOP特征二：继承性"></a>OOP特征二：继承性</h3><p>方法的重写(override)</p>
<p>关键字：super</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%BA%8C/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%80/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%80/" class="post-title-link" itemprop="url">面向对象一</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-11-30 00:00:00" itemprop="dateCreated datePublished" datetime="2020-11-30T00:00:00+08:00">2020-11-30</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2020-12-07 14:47:23" itemprop="dateModified" datetime="2020-12-07T14:47:23+08:00">2020-12-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/javaSE/" itemprop="url" rel="index"><span itemprop="name">javaSE</span></a>
        </span>
    </span>

  
    <span id="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%80/" class="post-meta-item leancloud_visitors" data-flag-title="面向对象一" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%80/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%80/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.2k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>4 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="面向过程-POP-与面向对象-OOP"><a href="#面向过程-POP-与面向对象-OOP" class="headerlink" title="面向过程(POP)与面向对象(OOP)"></a>面向过程(POP)与面向对象(OOP)</h3><ol>
<li>面向过程，强调的是功能行为，以函数为最小单位，考虑怎么做。</li>
<li>面向对象：将功能封装进对象，强调具备了功能的对象，以类/对象为最小单位，考虑谁来做</li>
<li>面向三大特征：<ul>
<li>封装</li>
<li>继承</li>
<li>多态</li>
</ul>
</li>
</ol>
<h3 id="Java基本元素：类和对象"><a href="#Java基本元素：类和对象" class="headerlink" title="Java基本元素：类和对象"></a>Java基本元素：类和对象</h3><ol>
<li><p>类和对象是面向对象的核心概念</p>
</li>
<li><p>类是对一类事物的描述，是抽象的、概念上的定义</p>
</li>
<li><p>对象是实际存在的该类事物的每个个体，因而也称为实例</p>
</li>
<li><p>万物皆对象</p>
</li>
<li><p>面向对象程序设计的重点是类的设计</p>
</li>
<li><p>类的成员：属性和行为，属性对应类中的成员变量，行为对应类中的成员方法</p>
</li>
<li><p>类点语法格式：</p>
<figure class="highlight actionscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">修饰符	<span class="class"><span class="keyword">class</span> 类名</span>&#123;</span><br><span class="line">	属性声明；</span><br><span class="line">	方法声明；</span><br><span class="line">&#125;</span><br><span class="line">修饰符是<span class="keyword">public</span>时，类可以被任意访问</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h3 id="对象的创建和使用"><a href="#对象的创建和使用" class="headerlink" title="对象的创建和使用"></a>对象的创建和使用</h3>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/11/30/java/java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B8%80/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F/" class="post-title-link" itemprop="url">冒泡排序</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-11-28 00:00:00" itemprop="dateCreated datePublished" datetime="2020-11-28T00:00:00+08:00">2020-11-28</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2020-12-07 15:10:47" itemprop="dateModified" datetime="2020-12-07T15:10:47+08:00">2020-12-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/" itemprop="url" rel="index"><span itemprop="name">读书笔记-- 《啊哈算法》</span></a>
        </span>
    </span>

  
    <span id="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F/" class="post-meta-item leancloud_visitors" data-flag-title="冒泡排序" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.2k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>4 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="冒泡排序"><a href="#冒泡排序" class="headerlink" title="冒泡排序"></a>冒泡排序</h3><ul>
<li>基本思想：每次比较两个相邻的元素，如果它们的顺序错误就把它们交换</li>
<li>原理：每一趟只能确定将一个数归位</li>
<li>如果有n个数进行排序，只需将 n-1 个数归位，也就是说要进行 n-1 趟操作，而“每一趟”都需要从第一位开始进行相邻两个数的比较，将较小的一个数放在后面，比较完毕后向后挪一位继续比较下面两个相邻数的大小，重复此步骤，直到最后一个尚未归位的数。</li>
</ul>
<h3 id="程序1：将5个无序的数-3-9-1-10-2，使用冒泡排序从小到大排序"><a href="#程序1：将5个无序的数-3-9-1-10-2，使用冒泡排序从小到大排序" class="headerlink" title="程序1：将5个无序的数 3    9     -1    10    2，使用冒泡排序从小到大排序"></a>程序1：将5个无序的数 3    9     -1    10    2，使用冒泡排序从小到大排序</h3><ol>
<li><p>分析：</p>
<p>第一轮：</p>
<figure class="highlight basic"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="symbol">3 </span><span class="number">9</span> -<span class="number">1</span> <span class="number">10</span> -<span class="number">2</span></span><br><span class="line"><span class="symbol">3 </span>-<span class="number">1</span> <span class="number">9</span> <span class="number">10</span> -<span class="number">2</span></span><br><span class="line"><span class="symbol">3 </span>-<span class="number">1</span> <span class="number">9</span> <span class="number">10</span> -<span class="number">2</span></span><br><span class="line"><span class="symbol">3 </span>-<span class="number">1</span> <span class="number">9</span> -<span class="number">2</span> <span class="number">10</span>  //第一大的数移到最后</span><br></pre></td></tr></table></figure>

<p>第二轮：　</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">-1</span>  <span class="number">3</span> <span class="number">9</span> <span class="number">-2</span> <span class="number">10</span></span><br><span class="line"><span class="number">-1</span>  <span class="number">3</span> <span class="number">9</span> <span class="number">-2</span> <span class="number">10</span></span><br><span class="line"><span class="number">-1</span>  <span class="number">3</span> <span class="number">-2</span> <span class="number">9</span> <span class="number">10</span> <span class="comment">//第二大的数就位</span></span><br></pre></td></tr></table></figure>

<p>第三轮：</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">-1</span> <span class="number">3</span> <span class="number">-2</span> <span class="number">9</span> <span class="number">10</span></span><br><span class="line"><span class="number">-1</span> <span class="number">-2</span>  <span class="number">3</span> <span class="number">9</span> <span class="number">10</span> <span class="comment">// 第三大的数就位</span></span><br></pre></td></tr></table></figure>

<p>第四轮：</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">-2</span> <span class="number">-1</span> <span class="number">3</span> <span class="number">9</span> <span class="number">10</span>  <span class="comment">// 全部就位</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>先进行第一轮排序：</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a[<span class="number">5</span>] = &#123; <span class="number">3</span>,<span class="number">9</span>,<span class="number">-1</span>,<span class="number">10</span>,<span class="number">-2</span> &#125;;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">4</span>; i++) &#123; <span class="comment">//第一轮，需要进行4次比较</span></span><br><span class="line">	<span class="keyword">if</span> (a[i] &gt; a[i + <span class="number">1</span>]) &#123;</span><br><span class="line">		<span class="keyword">int</span> t = a[i];</span><br><span class="line">		a[i] = a[i + <span class="number">1</span>];</span><br><span class="line">		a[i + <span class="number">1</span>] = t;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;第一轮排序后：&quot;</span>);</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, a[i]);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>第一轮排序后：3 -1 9 -2 10</p>
</blockquote>
</li>
<li><p>第一轮排序需要比较4次，第二轮排序需要比较3次，第三轮排序需要比较2次，第四轮排序需要比较1次，因此第 i 轮排序，需要比较（n-i）次，i从1开始。</p>
</li>
<li><p>C代码</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">	<span class="keyword">int</span> a[<span class="number">5</span>] = &#123; <span class="number">3</span>,<span class="number">9</span>,<span class="number">-1</span>,<span class="number">10</span>,<span class="number">-2</span> &#125;;</span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;=<span class="number">4</span>; i++) &#123; <span class="comment">//共进行4轮比较</span></span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; (<span class="number">5</span> - i); j++) &#123; <span class="comment">//第i轮比较，比较(n-i)次，如第1轮比较，比较4次;</span></span><br><span class="line">			<span class="keyword">if</span> (a[j] &gt; a[j + <span class="number">1</span>]) &#123;</span><br><span class="line">				<span class="keyword">int</span> t = a[j];</span><br><span class="line">				a[j] = a[j + <span class="number">1</span>];</span><br><span class="line">				a[j + <span class="number">1</span>] = t;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;第%d轮排序后：&quot;</span>, i);</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">			<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, a[i]);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>输出：</p>
<p>第1轮排序后：3 -1 9 -2 10<br>第2轮排序后：-1 3 -2 9 10<br>第3轮排序后：-1 -2 3 9 10<br>第4轮排序后：-2 -1 3 9 10</p>
</blockquote>
</li>
<li><p>python代码</p>
<blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">a = [<span class="number">3</span>, <span class="number">9</span>, <span class="number">-1</span>, <span class="number">10</span>, <span class="number">-2</span>]</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">4</span>):</span><br><span class="line">    <span class="keyword">for</span> j <span class="keyword">in</span> range(<span class="number">4</span> - i):  <span class="comment"># 第0轮循环，需要比较4次;第1轮循环，需要比较3次</span></span><br><span class="line">        <span class="keyword">if</span> (a[j] &gt; a[j + <span class="number">1</span>]):</span><br><span class="line">            t = a[j]</span><br><span class="line">            a[j] = a[j + <span class="number">1</span>]</span><br><span class="line">            a[j + <span class="number">1</span>] = t</span><br><span class="line">    print(<span class="string">f&#x27;第<span class="subst">&#123;i + <span class="number">1</span>&#125;</span>轮循环后:<span class="subst">&#123;a&#125;</span>&#x27;</span>)</span><br></pre></td></tr></table></figure>

<p>输出：</p>
<p>第1轮循环后:    [3, -1, 9, -2, 10]<br>第2轮循环后:    [-1, 3, -2, 9, 10]<br>第3轮循环后:    [-1, -2, 3, 9, 10]<br>第4轮循环后:    [-2, -1, 3, 9, 10]</p>
</blockquote>
</li>
</ol>
<h3 id="程序2：输入-n-表示n个数）以及-n个待排序的数，输出进行从小到大冒泡排序后的结果"><a href="#程序2：输入-n-表示n个数）以及-n个待排序的数，输出进行从小到大冒泡排序后的结果" class="headerlink" title="程序2：输入:n(表示n个数）以及 n个待排序的数，输出进行从小到大冒泡排序后的结果"></a>程序2：输入:n(表示n个数）以及 n个待排序的数，输出进行从小到大冒泡排序后的结果</h3>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/" class="post-title-link" itemprop="url">快速排序</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-11-28 00:00:00" itemprop="dateCreated datePublished" datetime="2020-11-28T00:00:00+08:00">2020-11-28</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2020-12-07 15:10:57" itemprop="dateModified" datetime="2020-12-07T15:10:57+08:00">2020-12-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/" itemprop="url" rel="index"><span itemprop="name">读书笔记-- 《啊哈算法》</span></a>
        </span>
    </span>

  
    <span id="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/" class="post-meta-item leancloud_visitors" data-flag-title="快速排序" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.2k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="程序1：对-6-1-2-7-9-3-4-5-10-8，这10个数进行排序"><a href="#程序1：对-6-1-2-7-9-3-4-5-10-8，这10个数进行排序" class="headerlink" title="程序1：对 6    1      2      7     9      3      4      5     10      8，这10个数进行排序"></a>程序1：对 6    1      2      7     9      3      4      5     10      8，这10个数进行排序</h3><p><strong>分析：</strong></p>
<ol>
<li>首先在这个序列中找一个基准数，如以第一个数6作为基准数，接下来将比6大的数放在6的右边，比6小的数放在6的左边</li>
<li>分别从“  6  1  2  7   9   3   4   5   10   8 ” 两端开始探测，先从右往左找一个小于6的数，再从左往右找一个大于6的数，然后交换它们。可以用两个变量 i  和 j ，分别指向序列最左边和最右边</li>
<li>刚开始的时候让哨兵i指向序列的最左边，即 i = 1，执行数字6；让哨兵 j 指向序列的最右边，即 j=10，指向数字8</li>
<li>首先哨兵 j 开始出动（因为此处设置的基准数是最左边的数，所有哨兵 j 先出动）。哨兵 j 一步一步向左挪动，即 j–，直到找到一个小于6的数停下来。</li>
<li>接下来哨兵 i 一步一步向右挪动，即 i++，直到找到一个大于6的数停下来</li>
<li>最后哨兵 j 停在了5面前，哨兵 i 停在了 7 面前，交换 5 和 7，交换后的序列是：  6 1  2  5  9   3  4  7  10  8</li>
<li>到此，第一次交换结束。接下来哨兵 j 继续向左挪动（注意每次必须是哨兵 j 先出发），哨兵 j 在4 面前停下来，哨兵 i 继续向右挪动，在 9 面前停下来，再次进行交换。第二次交换后的序列为：   6 1  2  5   4  3  9  7   10  8</li>
<li>第二次交换结束，继续探测。哨兵 j 继续向左，在 3 面前停下，哨兵 i 继续向右，此时哨兵 i 和 哨兵 j 在 3 面前相遇了，说明此时 探测结束，将基准数 6 和 3进行交换，交换后的序列为：  3 1  2  5  4   6  9   7  10  8</li>
<li>到此第一轮探测真正结束，此时以基准数6为分界点，6左边的数都小于6,   6右边的数都大于6。基准数 6 归位。</li>
<li>接下来以同样的方式处理6左边的序列和6右边的序列。</li>
</ol>
<h3 id="过程："><a href="#过程：" class="headerlink" title="过程："></a>过程：</h3><ol>
<li><p>初始序列：6   1   2   7   9   3    4    5   10    8</p>
</li>
<li><p>以6为基准数</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">6</span>   <span class="number">1</span>    <span class="number">2</span>  <span class="number">7</span>   <span class="number">9</span>   <span class="number">3</span>    <span class="number">4</span>    <span class="number">5</span>   <span class="number">10</span>    <span class="number">8</span></span><br><span class="line">① i=<span class="number">6</span>，j=<span class="number">8</span>，j移动到<span class="number">5</span>，i移动到<span class="number">7</span>，交换<span class="number">5</span>和<span class="number">7</span></span><br><span class="line">	<span class="number">6</span>   <span class="number">1</span>   <span class="number">2</span>   <span class="number">5</span>   <span class="number">9</span>   <span class="number">3</span>    <span class="number">4</span>    <span class="number">7</span>   <span class="number">10</span>    <span class="number">8</span></span><br><span class="line">② i=<span class="number">5</span>，j=<span class="number">7</span>，j移动到<span class="number">4</span>，i移动到<span class="number">9</span>，交换<span class="number">4</span>和<span class="number">9</span></span><br><span class="line">	<span class="number">6</span>   <span class="number">1</span>   <span class="number">2</span>   <span class="number">5</span>   <span class="number">4</span>   <span class="number">3</span>    <span class="number">9</span>    <span class="number">7</span>   <span class="number">10</span>    <span class="number">8</span></span><br><span class="line">③ i=<span class="number">4</span>，j=<span class="number">9</span>，j移动到<span class="number">3</span>，i移动到<span class="number">3</span>，i和j相遇，将<span class="number">6</span>和<span class="number">3</span>交换，<span class="number">6</span>归位</span><br><span class="line">	<span class="number">3</span>   <span class="number">1</span>   <span class="number">2</span>   <span class="number">5</span>   <span class="number">4</span>   <span class="number">6</span>    <span class="number">9</span>    <span class="number">7</span>   <span class="number">10</span>    <span class="number">8</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>将 6 左边的序列进行归并排序</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">3</span>   <span class="number">1</span>   <span class="number">2</span>   <span class="number">5</span>   <span class="number">4</span></span><br><span class="line">①以<span class="number">3</span>为基准数，<span class="number">3</span>归位后：<span class="number">2</span>   <span class="number">1</span>   <span class="number">3</span>   <span class="number">5</span>   <span class="number">4</span></span><br><span class="line">②将<span class="number">3</span>左边排序：<span class="number">1</span>   <span class="number">2</span>   <span class="number">3</span>   <span class="number">5</span>   <span class="number">4</span></span><br><span class="line">③将<span class="number">3</span>右边排序：<span class="number">1</span>   <span class="number">2</span>   <span class="number">3</span>   <span class="number">4</span>   <span class="number">5</span></span><br><span class="line">④得到<span class="number">6</span>左边的序列：<span class="number">1</span>   <span class="number">2</span>   <span class="number">3</span>   <span class="number">4</span>   <span class="number">5</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>将6 右边的序列进行归并排序</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">9</span>    <span class="number">7</span>   <span class="number">10</span>    <span class="number">8</span></span><br><span class="line">①以<span class="number">9</span>为基准数，<span class="number">9</span>归位后：<span class="number">8</span>  <span class="number">7</span>  <span class="number">9</span>  <span class="number">10</span></span><br><span class="line">②将<span class="number">9</span>左边排序：<span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span>  <span class="number">10</span></span><br><span class="line">③将<span class="number">9</span>右边排序：<span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span>  <span class="number">10</span></span><br><span class="line">④得到<span class="number">6</span>右边的序列：<span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span>  <span class="number">10</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
</li>
<li><p>排序结果：1   2   3   4   5   6    7   8   9   10</p>
</li>
</ol>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/11/28/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/27/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E7%AE%80%E5%8C%96%E7%89%88%E6%A1%B6%E6%8E%92%E5%BA%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/27/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E7%AE%80%E5%8C%96%E7%89%88%E6%A1%B6%E6%8E%92%E5%BA%8F/" class="post-title-link" itemprop="url">桶排序</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-11-27 00:00:00" itemprop="dateCreated datePublished" datetime="2020-11-27T00:00:00+08:00">2020-11-27</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2020-12-07 15:11:04" itemprop="dateModified" datetime="2020-12-07T15:11:04+08:00">2020-12-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/" itemprop="url" rel="index"><span itemprop="name">读书笔记-- 《啊哈算法》</span></a>
        </span>
    </span>

  
    <span id="/2020/11/27/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E7%AE%80%E5%8C%96%E7%89%88%E6%A1%B6%E6%8E%92%E5%BA%8F/" class="post-meta-item leancloud_visitors" data-flag-title="桶排序" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/27/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E7%AE%80%E5%8C%96%E7%89%88%E6%A1%B6%E6%8E%92%E5%BA%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/27/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E7%AE%80%E5%8C%96%E7%89%88%E6%A1%B6%E6%8E%92%E5%BA%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.2k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>4 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="程序1：将5个同学的分数5-3-5-2-8（满分10分）进行从小到大排序输出"><a href="#程序1：将5个同学的分数5-3-5-2-8（满分10分）进行从小到大排序输出" class="headerlink" title="程序1：将5个同学的分数5,3,5,2,8（满分10分）进行从小到大排序输出"></a>程序1：将5个同学的分数5,3,5,2,8（满分10分）进行从小到大排序输出</h3><h3 id="分析："><a href="#分析：" class="headerlink" title="分析："></a>分析：</h3><ol>
<li>可以借助一个一维数组</li>
<li>首先申请一个大小为11的数组 int a [11]，就有了11个变量 a[0] 到 a[10]，a[k] = v 表示得 k 分的人有 v个</li>
<li>然后将 a[0] 到 a[10] 都初始化为0，表示得0-10分的人都为0，这些分数还没有人得</li>
<li>接着处理一个分数，如第一个人的分数是5分，则让 a[5] 自增1，表示5这个分数出现了一次，以此类推处理所有的分数</li>
<li>最后的数组 a的值就是 0-10，分数范围的各个分数出现的次数，将出现过的分数打印出来即可，出现几次打印几次。如 a[2] =1 就把2这个分数打印1次。</li>
</ol>
<p><strong>c代码：</strong></p>
<ol>
<li><p>申请一个长度为11的数组a，并定义一个 score数组保存所有学生的分数</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a[<span class="number">11</span>];</span><br><span class="line"><span class="keyword">int</span> score[] = &#123; <span class="number">5</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">2</span>,<span class="number">8</span> &#125;;</span><br></pre></td></tr></table></figure>
</blockquote>
</li>
<li><p>将数组a初始化</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">11</span>; i++) &#123;</span><br><span class="line">	a[i] = <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</blockquote>
</li>
<li><p>处理每一个分数</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">	<span class="keyword">int</span> item = score[i];</span><br><span class="line">	a[item] += <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</blockquote>
</li>
<li><p>打印输出</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">11</span>; i++) &#123;</span><br><span class="line">	<span class="comment">//printf(&quot;%d &quot;, a[i]);  0 0 1 1 0 2 0 0 1 0 0</span></span><br><span class="line">	<span class="keyword">if</span> (a[i] != <span class="number">0</span>) &#123;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; a[i]; j++) &#123;</span><br><span class="line">			<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, i);  <span class="comment">//2 3 5 5 8</span></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这里 if 判断可不用，若a[i] = 0，将不会进行for循环打印输出</p>
</blockquote>
</li>
<li><p>完整代码：</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">	<span class="comment">//1，申请一个大小为11的数组a[11]，11个变量a[0]~a[10]</span></span><br><span class="line">	<span class="keyword">int</span> a[<span class="number">11</span>];</span><br><span class="line">	<span class="keyword">int</span> score[] = &#123; <span class="number">5</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">2</span>,<span class="number">8</span> &#125;;</span><br><span class="line"></span><br><span class="line">	<span class="comment">//2，将a[0]到a[10]初始化为0，表示这些分数没有人得过</span></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">11</span>; i++) &#123;</span><br><span class="line">		a[i] = <span class="number">0</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">//3，处理每一个人的分数，如，第一个人是5分，将a[5]加1</span></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">		<span class="keyword">int</span> item = score[i];</span><br><span class="line">		a[item] += <span class="number">1</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="comment">//4，将出现过的分数打印出来即可（出现几次打印几次），如a[2]=1,将2打印1次</span></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">11</span>; i++) &#123;</span><br><span class="line">		<span class="comment">//printf(&quot;%d &quot;, a[i]);  0 0 1 1 0 2 0 0 1 0 0</span></span><br><span class="line">		<span class="keyword">if</span> (a[i] != <span class="number">0</span>) &#123;</span><br><span class="line">			<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; a[i]; j++) &#123;</span><br><span class="line">				<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, i);  <span class="comment">//2 3 5 5 8</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>输出：2 3 5 5 8</p>
</blockquote>
</li>
</ol>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/11/27/%E3%80%8A%E5%95%8A%E5%93%88%E7%AE%97%E6%B3%95%E3%80%8B/%E7%AE%80%E5%8C%96%E7%89%88%E6%A1%B6%E6%8E%92%E5%BA%8F/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/jQuery%E9%80%89%E6%8B%A9%E5%99%A8%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/jQuery%E9%80%89%E6%8B%A9%E5%99%A8%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0/" class="post-title-link" itemprop="url">未命名</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2020-11-22 20:23:14 / 修改时间：22:03:05" itemprop="dateCreated datePublished" datetime="2020-11-22T20:23:14+08:00">2020-11-22</time>
    </span>

  
    <span id="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/jQuery%E9%80%89%E6%8B%A9%E5%99%A8%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0/" class="post-meta-item leancloud_visitors" data-flag-title="" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/jQuery%E9%80%89%E6%8B%A9%E5%99%A8%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/jQuery%E9%80%89%E6%8B%A9%E5%99%A8%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.4k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.3.1/jquery.js"></script>
    <style>
        div,span,p{
            width: 140px;
            height: 140px;
            margin:5px;
            background:#aaa;
            border:#000 1px solid;
            float:left;
            font-size:17px;
            font-family: Verdana;
        }
        div.mini{
            width:55px;
            height: 55px;
            background-color: #aaa;
            font-size:12px;
        }
        div.hide{
            display: none;
        }
    </style>
</head>
<body>
    <div class="one" id="one">
        id为one,class为one的div
        <div class="mini">class为mini</div>
    </div>
    <div class="one" id="two" title="test">
        id为two,class为one，title为test的div
        <div class="mini" title="other">class为mini，title为other</div>
        <div class="mini" title="test">class为mini，title为test</div>
    </div>
    <div class="one">
        <div class="mini">class为mini</div>
        <div class="mini">class为mini</div>
        <div class="mini">class为mini</div>
        <div class="mini"></div>
    </div>
    <div class="one">
        <div class="mini">class为mini</div>
        <div class="mini">class为mini</div>
        <div class="mini">class为mini</div>
        <div class="mini" title="test">class为mini，title为test</div>
    </div>
    <div  style="display: none;">style的display为"none"的div</div>
    <div class="hide">class为hide的div</div>
    <div>
        包含input的type为"hidden"的div
        <input type="hidden" size="8">
    </div>
    <span id="mover">正在执行动画的span元素</span>
</body>
</html>
<script>
    //基本选择器

    //1,改变id为one的元素的背景色
    //$("#one").css("background","#bbffaa");

    //2,改变class为mini的所有元素的背景色
    //$(".mini").css("background","#bbffaa");

    //3,改变元素名是div的所有元素的背景色
    //$("div").css("background","#bbffaa");

    //4，改变所有元素的背景色
    //$("*").css("background","#bbffaa");

    //5，改变所有的span元素和id为two的元素的背景色
    //$("span,#two").css("background","#bbffaa");

    
    //层次选择器
    //1,改变body内所有div的背景色
    //$("body div").css("background","#bbffaa");

    //2,改变body内子div元素的背景色
    //$("body>div").css("background","#bbffaa");

    //3,改变class为one的下一个div元素背景色
    //$(".one+div").css("background","#bbffaa");
    //$(".one").next("div").css("background","#bbffaa");

    //4,改变id为two的元素后面的所有div兄弟元素的背景色
    //$("#two~div").css("background","#bbffaa");
    //$("#two").nextAll("div").css("background","#bbffaa");

   //siblings()方法
   //$("#two").siblings("div").css("background","#bbffaa");


   //过滤选择器
   //1,基本过滤选择器
    //①改变第一个div元素的背景色
    //$("div:first").css("background","#bbffaa");

    //②改变最后一个div元素的背景色
    //$("div:last").css("background","#bbffaa")

    //③改变class不为one的元素的背景色
    //$("div:not(.one)").css("background","#bbffaa");

    //⑤改变索引值为偶数的div元素的背景色
    //$("div:even").css("background","#bbffaa");

    //⑥改变索引值为奇数的div元素的背景色
    //$("div:odd").css("background","#bbffaa");

    //⑥改变索引值等于3的div元素的背景色
    //$("div:eq(3)").css("background","#bbffaa");

    //⑦改变索引值大于3的div元素的背景色
    //$("div:gt(3").css("background","#bbffaa");

    //⑧改变索引值小于3的div元素的背景色
    //$("div:lt(3").css("background","#bbffaa");

    //⑨改变所有标题元素的背景色
    //$(":header").css("background","#bbffaa");

    //⑩改变当前正在执行动画的元素的背景色
    //$(":animated").css("background","#bbffaa");


   //2，内容过滤选择器
   //①改变含有文本"di"的div元素的背景色
   //$("div:contains('di')").css("background","#bbffaa");

   //②改变不包含子元素（包括文本元素）的div空元素的背景色
   //$("div:empty").css("background","#bbffaa");

   //③改变含有class为mini元素的div元素的背景色
   //$("div:has('.mini')").css("background","#bbffaa");

   //④改变含有子元素（包括文本元素）的div元素的背景色
   //$("div:parent").css("background","#bbffaa");

   //3，可见性过滤选择器
   //①改变所有可见的div元素的背景色
   // $("div:visible").css("background","#ff6500");

   //②显示隐藏的div元素
   $("div:hidden").show(3000);
</script>
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%BE%93%E5%87%BA%E9%80%89%E4%B8%AD%E5%A4%9A%E9%80%89%E6%A1%86%E7%9A%84%E4%B8%AA%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%BE%93%E5%87%BA%E9%80%89%E4%B8%AD%E5%A4%9A%E9%80%89%E6%A1%86%E7%9A%84%E4%B8%AA%E6%95%B0/" class="post-title-link" itemprop="url">未命名</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2020-11-22 20:16:59 / 修改时间：20:22:09" itemprop="dateCreated datePublished" datetime="2020-11-22T20:16:59+08:00">2020-11-22</time>
    </span>

  
    <span id="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%BE%93%E5%87%BA%E9%80%89%E4%B8%AD%E5%A4%9A%E9%80%89%E6%A1%86%E7%9A%84%E4%B8%AA%E6%95%B0/" class="post-meta-item leancloud_visitors" data-flag-title="" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%BE%93%E5%87%BA%E9%80%89%E4%B8%AD%E5%A4%9A%E9%80%89%E6%A1%86%E7%9A%84%E4%B8%AA%E6%95%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%BE%93%E5%87%BA%E9%80%89%E4%B8%AD%E5%A4%9A%E9%80%89%E6%A1%86%E7%9A%84%E4%B8%AA%E6%95%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>144</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="checkbox" value="1" name="check" checked>
    <input type="checkbox" value="2" name="check">
    <input type="checkbox" value="3" name="check" checked>
    <input type="button" value="选中的个数" id="btn">
</body>
</html>
<script>
    var btn=document.getElementById("btn");
    btn.onclick=function(){
        var arr=new Array();
        var items=document.getElementsByName("check");
        for(var i=0;i<items.length;i++){
            if(items[i].checked){
                arr.push(items[i].value);
            }
        }
        console.log(arr) // (2) ["1", "3"]
        console.log("选中的个数是：",arr.length) //2
    }
</script>
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  

      
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/shanlu123/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%A1%A8%E6%A0%BC%E9%9A%94%E8%A1%8C%E5%8F%98%E8%89%B2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="shanlu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shanlu的博客">
    </span>

    
    
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%A1%A8%E6%A0%BC%E9%9A%94%E8%A1%8C%E5%8F%98%E8%89%B2/" class="post-title-link" itemprop="url">未命名</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2020-11-22 20:11:47 / 修改时间：20:16:34" itemprop="dateCreated datePublished" datetime="2020-11-22T20:11:47+08:00">2020-11-22</time>
    </span>

  
    <span id="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%A1%A8%E6%A0%BC%E9%9A%94%E8%A1%8C%E5%8F%98%E8%89%B2/" class="post-meta-item leancloud_visitors" data-flag-title="" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%A1%A8%E6%A0%BC%E9%9A%94%E8%A1%8C%E5%8F%98%E8%89%B2/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/22/%E3%80%8A%E9%94%8B%E5%88%A9%E7%9A%84jQuery%E3%80%8B/code/%E7%AC%AC%E4%BA%8C%E7%AB%A0/%E8%A1%A8%E6%A0%BC%E9%9A%94%E8%A1%8C%E5%8F%98%E8%89%B2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>225</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.3.1/jquery.js"></script>
</head>
<body>
    <table id="tb">
        <tbody>
            <tr>
                <td>第一行</td>
                <td>第一行</td>
            </tr>
            <tr>
                <td>第二行</td>
                <td>第二行</td>
            </tr>
            <tr>
                <td>第三行</td>
                <td>第三行</td>
            </tr>
            <tr>
                <td>第四行</td>
                <td>第四行</td>
            </tr>
            <tr>
                <td>第五行</td>
                <td>第五行</td>
            </tr>
            <tr>
                <td>第六行</td>
                <td>第六行</td>
            </tr>
        </tbody>
    </table>
</body>
</html>
<script>
    var tb=document.getElementById("tb"); //获取table
    var tbody=document.getElementsByTagName("tbody")[0]; //表格中第一个tbody元素
    var trs=document.getElementsByTagName('tr');//tbody下所有的tr元素
    for(var i=0;i<trs.length;i++){
        if(i%2==0){
            trs[i].style.backgroundColor="#888";
        }
    }
</script>
      
    </div>

    
    
    

    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/5/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><span class="page-number current">6</span><a class="page-number" href="/page/7/">7</a><span class="space">&hellip;</span><a class="page-number" href="/page/13/">13</a><a class="extend next" rel="next" href="/page/7/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



      

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">
      

      

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">shanlu</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">225k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">3:25</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>


    <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    </div>
  </footer>

  
  <script size="300" alpha="0.6" zIndex="-1" src="//cdn.jsdelivr.net/npm/ribbon.js@1.0.2/dist/ribbon.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.0/lib/anime.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  <script src="/js/local-search.js"></script>















  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>








  

  
<script>
NexT.utils.loadComments('#valine-comments', () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js', () => {
    new Valine(Object.assign({
      el  : '#valine-comments',
      path: "/page/6/",
    }, {"enable":true,"appId":"M0TTE46ti90I3BUUJqD5WYyD-gzGzoHsz","appKey":"UelegRsJXosPYDakAbUdO5e8","notify":true,"verify":false,"placeholder":"留下评论吧","avatar":"mm","meta":["nick","mail","link"],"pageSize":10,"lang":"zh-cn","visitor":true,"comment_count":true,"recordIP":false,"serverURLs":null,"enableQQ":false,"requiredFields":[]}
    ));
  }, window.Valine);
});
</script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":225,"height":450},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body>
</html>
